from PyQt5.QtWidgets import QProgressBar
from PyQt5.QtCore import QTimer

class ProgressBar(QProgressBar):
    def __init__(self):
        super().__init__()
        self.setup_ui()
        self.setRange(0, 100)
        self.setValue(0)
        
    def setup_ui(self):
        self.setRange(0, 100)
        self.setValue(0)
        self.setTextVisible(True)
        self.hide()
        
        self.timer = QTimer()
        self.timer.timeout.connect(self._update_progress)
        self.current_progress = 0
    
    def start_progress(self):
        """开始进度条"""
        self.show()
        self.current_progress = 0
        self.setValue(0)
        self.timer.start(200)  # 每200ms更新一次
    
    def _update_progress(self):
        """更新进度条"""
        self.current_progress += 5
        self.setValue(self.current_progress)
        
        if self.current_progress >= 100:
            self.timer.stop()
    
    def reset(self):
        """重置进度条"""
        self.timer.stop()
        self.hide()
        self.setValue(0)